using System;
using System.Collections.Generic;
using System.Text;
using UTLDB;
using System.Collections;
using System.Windows.Forms;

namespace frmKiemKho
{
    public class CBarcode :IComparer<CBarcode>
    {
        private string _barcodeDate;
        private string _barcode;
        private string _barcodeNumber;
        public CBarcode()
        { }
        public string BarCodeDate
        {
            get { return _barcodeDate; }
            set { _barcodeDate = value; }
        }
        public string BarCode
        {
            get { return _barcode; }
            set { _barcode = value; }
        }
        public string BarCodeNumber
        {
            get { return _barcodeNumber; }
            set { _barcodeNumber = value; }
        }





        #region IComparer<CBarcode> Members

        public bool Compare(CBarcode x, CBarcode y)
        {
            if (x.BarCode == y.BarCode) return true;
            return false;
        }

        #endregion

        #region IComparer<CBarcode> Members

        int IComparer<CBarcode>.Compare(CBarcode x, CBarcode y)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion
    }

    public class CReadBarcode
    {
        private string _path;
        public CReadBarcode()
        {
        }
        public string PathFile
        {
            set { _path = value; }
            get { return _path; }
        }
        public ArrayList ReadBarCode()
        {
            ArrayList arrBarcode = new ArrayList();
            ArrayList arrResult = new ArrayList();
            arrBarcode = UTLTEXT.ReadText(PathFile);
            //1710   8935013160309                   1  
            if (arrBarcode.Count > 0)
            {
                for (int i = 0; i < arrBarcode.Count; i++)
                {
                    string[] ar = arrBarcode[i].ToString().Split(' ');
                    bool flgDate = true;
                    bool flgBarCode = true;
                    bool flgNum = true;
                    CBarcode __barcode = new CBarcode();
                    for (int j = 0; j < ar.Length; j++)
                    {
                        if (j == ar.Length - 1)
                        {
                            arrResult.Add(__barcode);
                        }
                        if (ar[j].Equals(""))
                        {
                            continue;
                        }

                        if (flgDate)
                        {
                            __barcode.BarCodeDate = UTLCOMMAND.CConvert.cvStringToDate(ar[j]);
                            //arrResult.Add(__barcode);
                            flgDate = false;
                            continue;
                        }
                        if (flgBarCode)
                        {
                            __barcode.BarCode = ar[j];
                            // arrResult.Add(__barcode);
                            flgBarCode = false;
                            continue;
                        }
                        if (flgNum)
                        {
                            __barcode.BarCodeNumber = ar[j];
                            //arrResult.Add(__barcode);
                            flgNum = false;
                            continue;
                        }


                    }

                }
                return arrResult;
            }
            return null;

        }

    }
}
